/**
 * [setCookie 设置 cookie]
 * @param    {[type]}                 name   [变量名，必选]
 * @param    {[type]}                 value  [变量值，必选]
 * @param    {[type]}                 exdays [过期日期，可选]
 */
function setCookie(name, value, exdays) {
    let cookie = name + "=" + value + ";";
    if (exdays) {
        let d = new Date();
        d.setTime(d.getTime() + (exdays * 60 * 60 * 1000));
        let expires = "expires=" + d.toGMTString();
        cookie = cookie + ' ' + expires;
    }
    document.cookie = cookie;
}

/**
 * [getCookie 获取 cookie]
 * @param    {[type]}                 cname [变量名，必选]
 * @return   {[type]}                 [返回值：变量值（字符串）]
 */
function getCookie(cname) {
    let name = cname + "=";
    let cookie = document.cookie.split(';');
    for (let i = 0, len = cookie.length; i < len; i++) {
        let c = cookie[i].trim();
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

/**
 * [checkCookie 查询 cookie]
 * @return   {[type]}       [如果有cookie就显示欢迎界面，没有cookie就设置当前用户的信息]
 */
function checkCookie(key) {
    let result = getCookie(key);
    if (result != "") {
        // alert("Welcome again " + username);
        return result;
    }
}